package cn.itcast.feign.clients.fallback;

import cn.itcast.feign.clients.UserClient;
import cn.itcast.feign.pojo.User;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户微服务远程调用失败降级逻辑
 *
 * @author: itheima
 * @create: 2022-04-28 14:57
 */
@Slf4j
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {

    /**
     * 服务降级逻辑
     *
     * @param cause
     * @return
     */
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            /**
             * 在调用方快速返回结果
             * @param id
             * @return
             */
            @Override
            public User findById(Long id) {
                log.error("查询用户异常：{}", cause);
                User user = new User();
                user.setUsername("我错了，我真错了！！！！");
                return user;
            }
        };
    }
}
